package com.example.demo.controller;

import com.example.demo.bean.StudentBean;
import com.example.demo.bean.User;
import com.example.demo.mapper.StudentDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    protected StudentDao studentDao;
    protected static final Logger logger = LoggerFactory.getLogger(UserController.class);
    @RequestMapping("/list")
    public String listUser(Model model) {
        List<User> userList = new ArrayList<User>();
        for (int i = 0; i < 10; i++) {
            userList.add(new User(i, "张三" + i, Integer.toString(20 + i), "中国广州"));
        }
        logger.error("数据源打印成功");
        model.addAttribute("users", userList);
        return "/user1/list";
    }

    @RequestMapping("/student")
    @ResponseBody
    public List<StudentBean> listStudent(Model model) {

        return studentDao.getStudentList();
    }


}
